package com.drug.mingkang.utils;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * <p>
 *  返回信息
 * </p>
 *
 * @author wcj
 * @since 2020/7/22 17:29
 */
@Component
@Scope("prototype")
public class ResponseMessage<T> {
    /**
     * 失败状态码
     */
    private static final int ERROR_CODE = 50;
    /**
     * 成功状态码
     */
    private static final int SUCCESS_CODE = 20;


    private int status;
    private String message;
    private T data;


    public ResponseMessage() {
    }

    public ResponseMessage(int status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public static ResponseMessage success(Object data) {
        return ResponseMessage.success("操作成功", data);
    }

    public static ResponseMessage error(String message) {
        return new ResponseMessage(ResponseMessage.ERROR_CODE, message, null);
    }

    public static ResponseMessage error(String message,Object data) {
        return new ResponseMessage(ResponseMessage.ERROR_CODE, message, data);
    }
    public static ResponseMessage success(String message) {
        return new ResponseMessage(ResponseMessage.SUCCESS_CODE, message, null);
    }

    public static ResponseMessage error() {
        return new ResponseMessage(ResponseMessage.ERROR_CODE, "操作失败", null);
    }

    public static ResponseMessage success() {
        return new ResponseMessage(ResponseMessage.SUCCESS_CODE, "操作成功", null);
    }

    public static ResponseMessage success(String message, Object data) {

        return new ResponseMessage(ResponseMessage.SUCCESS_CODE, message, data);
    }

    public static int getErrorCode() {
        return ERROR_CODE;
    }

    public static int getSuccessCode() {
        return SUCCESS_CODE;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
